<template>
	<view>
		<uni-search-bar placeholder="搜索活动" @confirm="shou" @cancel="getlun()" @clear="getlun()"></uni-search-bar>
		<uni-card v-for="(item,index) in huo" :title="item.title" @click="duanxian(item.id)">
			<view class="">
				承办单位:{{item.undertaker}}
			</view>
			<view class="">
				活动开始时间:{{item.startAt}}
			</view>
			<view class="">
				人员要求:{{item.requireText}}
			</view>
			<br>
			<button type="primary" @click.stop="bapn(item.id)">报名</button>
		</uni-card>
		<uni-group style="position: fixed;bottom: 0%;right: 0%;left: 0%;z-index: 99;">
			<view class="item-container">
				<view class="thumb-box" v-for="(item1, index1) in list" :key="index1" @click.stop="dian(item1.link)">
					<image class="item-menu-image" :src="item1.image" mode=""></image>
					<view class="item-menu-name">{{item1.text}}</view>
				</view>
			</view>
		</uni-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				base: 'http://10.50.170.216:10001',
				huo: [],
				list: [{
						image: '../../../../static/uview/example/js_select_bak.png',
						text: '首页',
						link: 'index'
					},
					{
						image: '../../../../static/uview/example/js_select_bak.png',
						text: '志愿活动',
						link: 'zhi'
					},
					{
						image: '../../../../static/uview/example/js_select_bak.png',
						text: '我的活动',
						link: 'my'
					},
				],
			}
		},
		onLoad() {
			this.base =uni.getStorageSync('serIP')
			this.getlun()
		},
		methods: {
			duanxian(id){
				uni.navigateTo({
					url:'xianq?id='+id
				})
			},
			shou(e){
				this.huo = this.huo.filter((item)=>{
					if(item.title.indexOf(e.value)>=0){
						return item
					}
				})
			},
			bapn(id) {
				this.$post(this.base + '/prod-api/api/volunteer-service/register',{
					"activityId":id,
					"newState": true
				}).then((res) => {
					if(res.code == 200){
						uni.showToast({
							title:'报名成功',
							icon:'none'
						})
					}else{
						uni.showToast({
							title:res.msg
						})
					}
				})
			},
			getlun() {
				this.$get(this.base + '/prod-api/api/volunteer-service/activity/list').then((res) => {
					this.huo = res.rows
				})
			},
			dian(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style>
	.item-container {
		display: flex;
		flex-wrap: wrap;
	}

	.thumb-box {
		width: 33.33%;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		margin-top: 20rpx;
	}

	.item-menu-image {
		width: 80rpx;
		height: 80rpx;
	}
</style>
